home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / digitr1a / modflash.bas < prev    next >
BASIC Source File  |  1999-07-14  |  8KB  |  231 lines

  1. Attribute VB_Name = "mdFlashcard"
  2. Option Explicit
  3.  
  4. Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
  5. Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
  6.  
  7. Public FlashContents As New Collection
  8. Public LoadedByRecord As Boolean
  9. Public MenuRecords As Integer
  10. Public OpenFile As String
  11. Public RecentFileList As New Collection
  12. Public Saved As Boolean
  13. Public SelRecord As Integer
  14. Public CardsPosition As Integer
  15.  
  16. Global Const BEGINCHARS = "-->>:"
  17. Global Const ERRTAG = "//*ERR//"
  18. Global Const HEADING = "FILEREC"
  19. Global Const HDRECNUM = "ENTRYCOUNT"
  20. Global Const INVCHARERR = "Cannot add entry: invalid characters."
  21. Global Const MAXRECORDNUM = 4
  22. Global Const MESSAGE = "Save changes to this file?"
  23. Global Const MSGDEF = " Definition"
  24. Global Const MSGSHOW = "Show"
  25. Global Const MSGWRD = " Word"
  26. Global Const NOMCHNG = "aeioun!?"
  27. Global Const NOMTAG = "+^"
  28. Global Const RECORDINI = "FSOFT.INI"
  29. Global Const SECTION = "FLASHCARD"
  30. Global Const SEPCHARS = "::"
  31. Global Const SEPCHAR = ";"
  32.  
  33. Function AreEntries() As Boolean
  34.     AreEntries = FlashContents.Count > 0
  35. End Function
  36.  
  37. Public Sub CheckForAccents(txtObject As TextBox)
  38. Dim Letter As String, i As Integer
  39.     i = InStr(1, txtObject, NOMTAG)
  40.     If i > 0 Then
  41.         Letter = Right(Left(txtObject, i - 1), 1)
  42.         txtObject.SelStart = i - 2
  43.         txtObject.SelLength = 3
  44.         If InStr(1, NOMCHNG, Letter) = 0 Then
  45.             txtObject.SelStart = i - 1
  46.             txtObject.SelLength = 2
  47.             txtObject.SelText = ""
  48.             Exit Sub
  49.         End If
  50.         Select Case Letter
  51.             Case "a"
  52.                 txtObject.SelText = "ß"
  53.             Case "e"
  54.                 txtObject.SelText = "Θ"
  55.             Case "i"
  56.                 txtObject.SelText = "φ"
  57.             Case "o"
  58.                 txtObject.SelText = "≤"
  59.             Case "u"
  60.                 txtObject.SelText = "·"
  61.             Case "n"
  62.                 txtObject.SelText = "±"
  63.             Case "!"
  64.                 txtObject.SelText = "í"
  65.             Case "?"
  66.                 txtObject.SelText = "┐"
  67.         End Select
  68.     End If
  69. End Sub
  70.  
  71. Public Sub CloseFile()
  72.     OpenFile = ""
  73.     Cards.ChangeMode False
  74.     DeleteEntries FlashContents
  75. End Sub
  76.  
  77. Public Sub DeleteEntries(ByRef DeleteCol As Collection)
  78. Dim i As Integer
  79.     For i = DeleteCol.Count To 1 Step -1
  80.         DeleteCol.Remove i
  81.     Next i
  82. End Sub
  83.  
  84. Function IsOpenFile() As Boolean
  85.     IsOpenFile = (OpenFile <> "")
  86. End Function
  87.  
  88. Public Function GetFileContents(FileName As String) As Boolean
  89. Dim NextLine As String
  90.     GetFileContents = True
  91.     On Error GoTo FoundError
  92.     DeleteEntries FlashContents
  93.     Open FileName For Input As #1
  94.     While Not EOF(1)
  95.         Line Input #1, NextLine
  96.         FlashContents.Add NextLine
  97.     Wend
  98.     Close
  99.     Cards.ChangeMode True
  100.     OpenFile = FileName
  101.     Cards.AddMenuRecord OpenFile, True
  102.     Exit Function
  103. FoundError:
  104.     GetFileContents = False
  105.     MsgBox "Error #" & Err.Number & ": " & Err.Description & ".", , Err.Source
  106.     If Err.Number = 53 Or Err.Number = 75 Then
  107.         If LoadedByRecord Then
  108.             RecentFileList.Remove SelRecord
  109.             Cards.ResetFileRecords
  110.         End If
  111.     End If
  112. End Function
  113.  
  114. Public Sub GetFileRecord()
  115. Dim i As Integer, j As Long, tmpStr As String
  116. Dim NumberExpected As Integer
  117.     DeleteEntries RecentFileList
  118.     tmpStr = Space$(100)
  119.     j = GetPrivateProfileString(SECTION, HDRECNUM, "0", tmpStr, Len(tmpStr), RECORDINI)
  120.     NumberExpected = Val(tmpStr)
  121.     For i = 1 To NumberExpected
  122.         tmpStr = Space$(100)
  123.         j = GetPrivateProfileString(SECTION, HEADING & i, ERRTAG, tmpStr, Len(tmpStr), RECORDINI)
  124.         tmpStr = Trim(tmpStr)
  125.         If tmpStr <> "" And InStr(1, tmpStr, ERRTAG) = 0 Then
  126.             RecentFileList.Add tmpStr
  127.         End If
  128.     Next i
  129.     PrintRecentFileEntries
  130. End Sub
  131.  
  132. Public Function GetHidden(EntryNumber As Integer) As String
  133. Dim TmpString As String, i As Integer
  134.     If Not AreEntries Then Exit Function
  135.     If Not IsContent(FlashContents(EntryNumber)) Then
  136.         FlashContents.Remove EntryNumber
  137.         Exit Function
  138.     End If
  139.     i = Len(FlashContents(EntryNumber)) - InStr(1, FlashContents(EntryNumber), SEPCHARS)
  140.     GetHidden = Right(FlashContents(EntryNumber), i - 1)
  141. End Function
  142.  
  143. Public Function GetRevealed(EntryNumber As Integer) As String
  144. Dim TmpString As String, i As Integer
  145.     If Not AreEntries Then Exit Function
  146.     If EntryNumber = 0 Then EntryNumber = 1
  147.     If Not IsContent(FlashContents(EntryNumber)) Then
  148.         FlashContents.Remove EntryNumber
  149.         Exit Function
  150.     End If
  151.     i = InStr(1, FlashContents(EntryNumber), SEPCHARS)
  152.     TmpString = Left(FlashContents(EntryNumber), i - 1)
  153.     GetRevealed = Right(TmpString, Len(TmpString) - Len(BEGINCHARS))
  154. End Function
  155.  
  156. Public Function IsContent(Contents As String) As Boolean
  157. Dim TmpString As String
  158.     IsContent = True
  159.     TmpString = BEGINCHARS & "*" & SEPCHARS & "*"
  160.     If Not Contents Like TmpString Then IsContent = False
  161. End Function
  162.  
  163. Sub PrintRecentFileEntries()
  164. Dim i As Integer
  165.     For i = 1 To RecentFileList.Count
  166.         Cards.AddMenuRecord RecentFileList(i)
  167.     Next i
  168. End Sub
  169.  
  170. Public Function SaveFileContents(FileName As String)
  171. Dim i As Integer
  172.     Saved = True
  173.     Open FileName For Output As #1
  174.     For i = 1 To FlashContents.Count
  175.         Print #1, FlashContents(i)
  176.     Next i
  177.     OpenFile = FileName
  178.     Close #1
  179. End Function
  180.  
  181. Public Sub SaveFileRecords()
  182. Dim i As Integer
  183.     For i = 1 To MenuRecords
  184.         WritePrivateProfileString SECTION, HEADING & i, CStr(RecentFileList(i)), RECORDINI
  185.     Next i
  186.     WritePrivateProfileString SECTION, HDRECNUM, CStr(MenuRecords), RECORDINI
  187. End Sub
  188.  
  189. Public Sub SelectAll(Text As TextBox)
  190.     Text.SelStart = 0
  191.     Text.SelLength = Len(Text)
  192. End Sub
  193.  
  194. Sub SortEntries(Optional InfoMode As Integer)
  195. Dim i As Integer, IsFlaw As Boolean
  196. Dim j As String, k As String, TmpString As String
  197.     Do
  198.         IsFlaw = False
  199.         DoEvents
  200.         For i = FlashContents.Count To 1 Step -1
  201.             If IsValidEntry(FlashContents, i) = True Then
  202.                 k = j
  203.                 j = GetInfo(i, InfoMode)
  204.                 If j > k And i < FlashContents.Count Then
  205.                     IsFlaw = True
  206.                     TmpString = FlashContents(i)
  207.                     FlashContents.Remove i
  208.                     FlashContents.Add (TmpString)
  209.                 End If
  210.             End If
  211.         Next i
  212.     Loop Until IsFlaw = False
  213. End Sub
  214.  
  215. Function GetInfo(Entry As Integer, Mode As Integer) As String
  216.     Mode = Mode Mod 2
  217.     If Mode = 0 Then GetInfo = GetRevealed(Entry)
  218.     If Mode = 1 Then GetInfo = GetHidden(Entry)
  219. End Function
  220.  
  221. Public Function IsValidEntry(Records As Collection, Entry As Integer)
  222.     IsValidEntry = True
  223.     If Entry > Records.Count Then IsValidEntry = False
  224.     If Entry < 1 Then IsValidEntry = False
  225.     If IsValidEntry = False Then Exit Function
  226.     If Not IsContent(Records(Entry)) Then
  227.         Records.Remove Entry
  228.         IsValidEntry = False
  229.     End If
  230. End Function
  231.